home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.517 < prev    next >
Text File  |  1992-02-06  |  4KB  |  146 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;\f2\fswiss Helvetica;\f3\fmodern Ohlfs;}
  2. \paperw11440
  3. \paperh6000
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 file icon getFileIconFor iconEntered\
  8. \
  9. Q:  How do you use the getFileIconFor:... method to get a bitmap?\
  10. \
  11. A:  Here's some sample code:\
  12. \
  13.  
  14. \f1\fs24     - workspaceBitmap:(char *)path\
  15.     \{\
  16.         int       ok, length;\
  17.         char       *tiffData;\
  18.         NXStream   *bitmapStream;\
  19.         id        bitmap;\
  20.       \
  21.         [appSpeaker setSendPort:NXPortFromName(NX_WORKSPACEREQUEST,NULL)];\
  22.         [appSpeaker getFileIconFor:path TIFF:&tiffData \
  23.         TIFFLength:&length ok:&ok];\
  24.       \
  25.         if (!ok) \
  26.      \{\
  27.       return nil;\
  28.         \}\
  29.     \
  30.         bitmapStream = NXOpenMemory(tiffData, length, NX_READONLY);\
  31.         if (!bitmapStream) \
  32.      \{\
  33.       return nil;\
  34.         \}\
  35.     \
  36.  
  37. \b #ifdef 1.0
  38. \b0 \
  39.         bitmap = [Bitmap newFromStream:bitmapStream];\
  40.  
  41. \b #else /* 2.0 */
  42. \b0 \
  43.      bitmap = [[NXImage alloc] initFromStream: bitmapStream];\
  44.  
  45. \b #endif
  46. \b0 \
  47.         NXClose(bitmapStream);\
  48.       \
  49.         return bitmap;\
  50.     \}\
  51.     \
  52.  
  53. \f0\b\fs28 Note that the ifdef for 1.0 is for illustration purposes only and is NOT defined in any NeXTstep include file.\
  54.  
  55. \f2\b0\fs24 \
  56. \
  57.  
  58. \f0\fs28 Q:  Inside of my 
  59. \f1\fs24 iconEntered:...
  60. \f0\fs28  method, I want to get the icon of the file that's being dragged into the window.  I tried sending the 
  61. \f1\fs24 getFileIconFor:...
  62. \f0\fs28  message to the Workspace but this doesn't work (my app hangs for awhile).  Librarian and Mail somehow can display the file's icon when the user drags it into their window.  How can I make this work?\
  63.  
  64. \f2\fs24 \
  65. \
  66.  
  67. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\f0\fs28\fc0 A:  Workspace calls made within 
  68. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\fs24 iconEntered:...
  69. \f2  
  70. \f0\fs28 result in deadlock:  the Workspace blocks waiting for your app to return from 
  71. \f1\fs24 iconEntered:...
  72. \f2  
  73. \f0\fs28 while your app blocks waiting for the Workspace to answer the 
  74. \f1\fs24 getFileIconFor:...
  75. \f0\fs28  message.  You must use PostScript to copy the bitmap image from the Workspace window into a bitmap.  Here's the PostScript code (which you should place in a .psw file):\
  76.  
  77. \f2\fs24 \
  78.     \
  79.  
  80. \f1     defineps copyIconPicture(int win; float x; float y; float w; float h)\
  81.     x y w h gsave win windowdeviceround gstate grestore 0 0 Copy composite\
  82.     endps\
  83.  
  84. \f2     \
  85.     \
  86.  
  87. \f0\fs28 Now, your iconEntered:... method should look something like this:\
  88.  
  89. \f2\fs24     \
  90.  
  91. \f1     - (int)iconEntered:(int)windowNum at:(double)x :(double)y\
  92.        iconWindow:(int)winNum\
  93.        iconX:(double)iconX\
  94.        iconY:(double)iconY\
  95.        iconWidth:(double)wid\
  96.        iconHeight:(double)hgt\
  97.        pathList:(char *)pathList    /* path of file */\
  98.     \{\
  99.        id    bitmap;\
  100.  
  101. \b #ifndef 1.0\
  102.  
  103. \b0        NXSize  rect;\
  104.  
  105. \b #endif\
  106. \
  107.  
  108. \b0 \
  109.  
  110. \b #ifdef 1.0        \
  111.  
  112. \b0        bitmap = [Bitmap newSize:wid :hgt type:NX_ALPHABITMAP];\
  113.  
  114. \b #else /* 2.0 */\
  115.        
  116. \b0 rect.width = wid;\
  117.        rect.height = hgt;
  118. \b \
  119.        
  120. \b0 bitmap = [[NXImage alloc] initSize: &rect];
  121. \b \
  122. #endif\
  123.  
  124. \b0        [bitmap lockFocus];\
  125.        copyIconPicture(winNum, (float) iconX, (float) iconY, (float) wid, \
  126.            (float) hgt);\
  127.        [bitmap unlockFocus];\
  128.         \
  129.        /* do whatever else needs to be done, then return */\
  130.         \
  131.        return self;\
  132.     \}\
  133.  
  134. \f2     \
  135.  
  136. \f0\b\fs28 Note that the ifdef for 1.0 is for illustration purposes only and is NOT defined in any NeXTstep include file.\
  137.  
  138. \f2\b0\fs24     \
  139.  
  140. \f0\fs28 QA517    \
  141. \
  142. Valid for 1.0\
  143. Valid for 2.0  (with differences noted)        \
  144. \
  145.  
  146.